package com.ss.android.newmedia.message;

import java.util.LinkedHashMap;
import java.util.Map.Entry;
import java.util.Map;

public final class aa {
    private final LinkedHashMap a;
    private int b;
    private int c;
    private int d;
    private int e;
    private int f;
    private int g;

    public aa() {
        this.c = 10;
        this.a = new LinkedHashMap(0, 0.75f, false);
    }

    public final synchronized void a() {
        int v0 = -1;
        this.a(v0);
    }

    public final synchronized Object a(Object arg3, Object arg4) {
        Object v0_1;
        if (arg3 != null) {
            ++this.d;
            ++this.b;
            v0_1 = this.a.put(arg3, arg4);
            if (v0_1 != null) {
                --this.b;
            }

            this.a(this.c);
            return v0_1;
        }
        throw new NullPointerException("key == null || value == null");
    }

    private void a(int arg4) {
        while (this.b > arg4) {
            if (this.a.isEmpty()) {
                break;
            }

            Object v0 = this.a.entrySet().iterator().next();
            if (v0 == null) {
                break;
            }

            Object v1 = ((Map.Entry) v0).getKey();
            ((Map.Entry) v0).getValue();
            this.a.remove(v1);
            --this.b;
            ++this.e;
        }

        if (this.b >= 0 && (!this.a.isEmpty() || this.b == 0)) {
            return;
        }

        throw new IllegalStateException(this.getClass().getName() + ".sizeOf() is reporting inconsistent results!");
    }

    public final synchronized Object a(Object arg3) {
        Object v0_1;
        if (arg3 != null) {
            v0_1 = this.a.get(arg3);
            if (v0_1 != null) {
                ++this.f;
            } else {
                ++this.g;
                v0_1 = null;
            }
            return v0_1;
        }
        throw new NullPointerException("key == null");
    }

    public final synchronized Object b(Object arg3) {
        Object v0_1;
        if (arg3 != null) {
            v0_1 = this.a.remove(arg3);
            if (v0_1 != null) {
                --this.b;
            }
            return v0_1;
        }
        throw new NullPointerException("key == null");
    }

    public final Map b() {
        return new LinkedHashMap(this.a);
    }

    public final synchronized String toString() {
        String v0_2;
        int v0 = 0;
        int v1 = this.f + this.g;
        if (v1 != 0) {
            v0 = this.f * 100 / v1;
        }

        v0_2 = String.format("LruCache[maxSize=%d,hits=%d,misses=%d,hitRate=%d%%]", Integer.valueOf(this.c), Integer.valueOf(this.f), Integer.valueOf(this.g), Integer.valueOf(v0));
        return v0_2;
    }
}

